<?php
include_once("functions/db_manipulate.php");

if (!init()) {
    redirect("login.php");
}

$fliesResultSet = getAllFlies();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Архив мушек</title>
    <link rel="stylesheet" type="text/css" href="css/navigation.css">
    <link rel="stylesheet" type="text/css" href="css/square.css">
    <link rel="stylesheet" type="text/css" href="css/menu.css">
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/flies.css">
    <script src="resources/jquery.js"></script>

    <meta charset="UTF-8">
</head>
<body class="body">

<?php
include_once("menu.php");
?>

<div id="square">
    <div class="fliesdiv">

        <?php
        $date = "";
        while ($fly = mysql_fetch_assoc($fliesResultSet)) {

            if ($fly['date'] != $date) {
                ?>
                <div class="fliesheader">
                    <?= $fly['date'] ?>
                </div>
                <?php
                $date = $fly['date'];
            }


            $comments = countFlyComments($fly['id']);
            ?>
            <div class="flydiv">
                <div class="flyheader">
                    <?= $fly['header'] ?>
                </div>

                <div class="flylegend">
                    <?= $fly['legend'] ?>
                </div>

                <div id="flyinfo">
                    <div id="author">
                        <?= $fly['author'] ?>
                    </div>
                    <div id="date">
                        <?= $fly['date'] ?>
                    </div>
                    <div id="date">
                        <?= $fly['time'] ?>
                    </div>
                </div>

                <div class="flybuttonsdiv">

                    <div class="flybutton"
                         onclick="location.href = 'fly_like_handler.php?fid=<?= $fly['id'] ?>&like=1'">
                        Like(<?= $fly['likes'] ?>)
                    </div>

                    <div class="flybutton"
                         onclick="location.href = 'fly_like_handler.php?fid=<?= $fly['id'] ?>&dislike=1'">
                        Dislike(<?= $fly['dislikes'] ?>)
                    </div>

                    <div class="flybutton" onclick="location.href = 'fly.php?fid=<?= $fly['id'] ?>'">
                        Comments(<?= $comments ?>)
                    </div>


                </div>
            </div>
        <?php
        }
        ?>
    </div>
</div>


<?php
include_once("navigation.html");
?>

</body>
</html>